import { generatorDynamicRouter } from "@/router/generator-routers";
import constantRouterMap from "@/router/base"


export default {
    state: {
        routers: constantRouterMap,
        addRouters: []
    },
    mutations: {
        SET_ROUTERS: (state, routers) => {
            state.addRouters = routers
            state.routers = constantRouterMap.concat(routers)
        }
    },
    actions: {
        // 异步路由
        asyncRouter({ commit, state }) {
            return new Promise((resolve, reject) => {
                generatorDynamicRouter().then(routers => {
                    commit('SET_ROUTERS', routers)
                    resolve(state.routers)
                })
            })

        }
    },
}